define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'events/sign/index' + location.search,
                    add_url: 'events/sign/add',
                    edit_url: 'events/sign/edit',
                    del_url: 'events/sign/del',
                    multi_url: 'events/sign/multi',
                    import_url: 'events/sign/import',
                    table: 'events_sign',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'title', title: __('Title'), operate: 'LIKE' },
                        { field: 'gender', title: __('Gender'), searchList: { "male": __('Gender male'), "female": __('Gender female') }, formatter: Table.api.formatter.normal },
                        { field: 'mobile', title: __('Mobile'), operate: 'LIKE' },
                        { field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images },
                        { field: 'state', title: __('State'), searchList: { "0": __('State 0'), "10": __('State 10'), "-1": __('State -1') }, formatter: Table.api.formatter.normal },
                        { field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'events_array.title', title: __('Events.title'), operate: 'LIKE' },
                        { field: 'category_name', title: __('Category.title'), operate: 'LIKE' },
                        { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            // if (Config.state == '0') {
            //     Controller.api.bindevent();
            // }
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
